package com.zenika.zenbinding.client.feedback;

import com.zenika.zenbinding.client.exception.DataMessage;
import com.zenika.zenbinding.client.handler.Handler;
import com.zenika.zenbinding.client.model.CellModel;

/**
 * This class is used to intercept a change in the state of a Renderer and
 * notify the CellModel of the changes.
 * @author Zenika
 */
public class DummyFeedbackManager implements FeedbackManager {

	private FeedbackManager manager;
	private CellModel model;

	/**
	 * Constructor.
	 * @param model CellModel to notify in case of state change of the managed
	 *        Renderer
	 */
	public DummyFeedbackManager(CellModel model) {
		this.model = model;
	}

	/**
	 * Notify both the CellModel and the FeedbackManager of the entrance of the
	 * renderer into the error state.
	 * @param message DataMessage coming from the DataException
	 * @param handler Handler associated with the renderer
	 */
	public void enterErrorState(DataMessage message, Handler handler) {
		// sent the message to the true manager
		if (this.manager != null) {
			this.manager.enterErrorState(message, handler);
		}
		// notify the table model
		this.model.fireError(message);
	}

	/**
	 * Notify both the CellModel and the FeedbackManager of the leaving of the
	 * renderer from the error state.
	 * @param handler Handler associated with the renderer
	 */
	public void leaveErrorState(Handler handler) {
		// sent the message to the true manager
		if (this.manager != null) {
			this.manager.leaveErrorState(handler);
		}
		// notify the table model
		this.model.fireErrorStop();
	}

	/**
	 * Set the FeedbackManager that has to be notified in case of change of
	 * state.
	 * @param manager FeedbackManager
	 */
	public void setFeedbackManager(FeedbackManager manager) {
		this.manager = manager;
	}

}
